/*
 *    Copyright 2021 FightingGuys Team
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package cn.fightingguys.kaiheila;

import cn.fightingguys.kaiheila.event.EventListener;

import java.util.List;

/**
 * KHL 框架用户抽象方法
 *
 * @author running_hyk
 * @version 1.0.0
 * @since 1.0.0
 */
public interface KHL {

    /**
     * {@link KHL} 框架内部状态码
     */
    enum Status {
        /**
         * KHL 模块初始化中
         */
        INITIALIZING,
        /**
         * 正在尝试登录账号
         */
        LOGGING_IN,
        /**
         * 完成所有事务
         */
        READY,
        /**
         * 用户密钥错误
         */
        FAILED_TO_LOGON
    }


    /**
     * 获取当前 KHL 实例内部{@link Status}状态码
     *
     * @return {@link Status} 状态码
     * @since 1.0.0
     */
    Status getKernelStatus();

    /**
     * {@link KHL} 进入某个状态之前，保持当前线程阻塞
     *
     * @param status {@link Status} 需要等待的状态
     * @see KHL#awaitReady()
     * @since 1.0.0
     */
    void awaitStatus(Status status);


    /**
     * {@link KHL} {@link Status#READY 就绪}之前，保持当前线程阻塞
     *
     * @see KHL#awaitStatus(Status)
     * @since 1.0.0
     */
    void awaitReady();

    // KHL 框架动态配置


    // Event Source -- 监听事件
    /**
     * 添加事件监听
     *
     * @param listener {@link EventListener} 事件监听类
     * @see KHL#getRegisteredListeners()
     * @see KHL#removeEventListener(EventListener)
     * @since 1.0.0
     */
    void addEventListener(EventListener listener);

    /**
     * 移除事件监听
     *
     * @param listener {@link EventListener} 事件监听类
     * @see KHL#addEventListener(EventListener)
     * @see KHL#getRegisteredListeners()
     * @since 1.0.0
     */
    void removeEventListener(EventListener listener);

    /**
     * 获取所有已经添加的监听器
     *
     * @return {@link EventListener} 事件监听类
     * @see KHL#addEventListener(EventListener)
     * @see KHL#getRegisteredListeners()
     * @since 1.0.0
     */
    List<EventListener> getRegisteredListeners();

}